#pragma once
#ifndef __MCGRAPHICSITEM_H_
#define __MCGRAPHICSITEM_H_

#include <IGraphicsItem.h>
#include <ICanvas.h>
#include <MCColor.h>
#include <qpainter.h>
#include <qgraphicsitem.h>

class MCGraphicsItem : public QGraphicsItem, public IGraphicsItem
{
public:

    MCGraphicsItem(ICanvas *presenter_);

    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
    virtual QRectF boundingRect() const override;
    virtual QPainterPath shape() const override;

    void setColor(const MCColor &color) override;
    void setFillColor(const MCColor &color) override;
    void setThickness(double thickness) override;
    void setLayerIndex(int layerIndex) override;

    bool isVisible();
    void select() override;
    void deselect() override;
    bool isSelected() override;
    void hoverEnter() override;
    void hoverLeave() override;
    void setHighlight(ItemHighlight highlight) override;
    void setVisible(ItemVisibility visibility) override;

    ICanvas *canvas();
    std::vector<IGripPoint *> grips() override;
    void setGripAt(IGripPoint *grip, const MCPoint2D &pos) override;
    void resetGrips() override;

protected:

    void setPainter(QPainter *painter);
    void initParams();

    ICanvas *presenter;
    std::vector<IGripPoint *> gripPoints;

protected:

    void drawLineSegment(const MCPoint2D &p1, const MCPoint2D &p2);
    void drawRect(const MCPoint2D &topLeft, const MCPoint2D &bottomRight);
    void drawCircle(const MCPoint2D &center, double radius);
    void drawEllipse(const MCPoint2D &center, double rx, double ry);
    void drawPoint(const MCPoint2D &point);
    void drawArc(const MCPoint2D &center, double radius, double startAngle, double spanAngle);
    void drawArrow2(const MCPoint2D &p1, const MCPoint2D &p2, double length, double sharpness, double scale = 1);
    void drawArrow(QPainter *painter, QPoint start, QPoint end, qreal arrowSize);
    void drawVector(const MCPoint2D &start, const MCVector2 &dir);
    void drawLabel(const MCPoint2D &topLeft, double width, double height, const std::string &pathToImage);

private:

    // QT
    QPainter *_painter;
    QPen _pen;

    // PARAMS
    ItemVisibility _visibility;
    MCColor _defaultColor;
    MCColor _defaultFillColor;
    MCColor _hoveredColor;
    MCColor _selectedColor;
    int _thickness;
    int _layerIndex;

    // FLAGS
    bool _isSelected;
};

#endif // !__MCGRAPHICSITEM_H_
